<template>
  <div class="right-container">
    <!-- 头部面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 表格区域 -->
    <el-card class="box-card">
      <el-table :data="rightsList" style="width: 100%" border stripe>
         <el-table-column type="index" label="#">
        </el-table-column>
        <el-table-column prop="authName" label="权限名称">
        </el-table-column>
        <el-table-column prop="path" label="路径">
        </el-table-column>
        <el-table-column prop="level" label="等级">
          <!-- 具名插槽 属性slot-scope="scope"，其中scope.row可以拿到表格绑定的数据-->
          <template slot-scope="scope">
            <el-tag v-if="scope.row.level === '0'">等级一</el-tag>
            <el-tag type="success" v-else-if="scope.row.level === '1'">等级二</el-tag>
            <el-tag type="warning" v-else>等级三</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
// 导入rightListAPI接口
import { rightsListAPI } from '@/api/rightsListAPI.js'
export default {
  name: 'Rights',
  data() {
    return {
      // 用来存储后台响应回来的权限列表数据
      rightsList: []
    }
  },
  methods: {
    // 获取权限列表数据
    async getRightsList() {
      const { data: res } = await rightsListAPI()
      // console.log(res)
      if (res.meta.status !== 200) return this.$message.error('获取权限列表失败')
      // console.log(res.data)
      this.rightsList = res.data
    }
  },
  created() {
    this.getRightsList()
  }
}
</script>

<style lang="less" scoped>
.el-card {
  margin-top: 15px;
}
</style>
